package com.dmzc.stage3.ThreadLocalMap;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class Test3 {
    public static void main(String[] args) {
        final int COUNT = 32;
        List<Hash> list = new ArrayList<>();
        for (int i = 0; i < COUNT; i++) {
            list.add(new Hash());
        }
        for (Hash hash : list) {
            System.out.print(hash.get()+"==");
        }

    }
}

class Hash {
    private final int threadLocalHashCode = nextHashCode();
    private static AtomicInteger nextHashCode =
            new AtomicInteger();
    private static final int HASH_INCREMENT = 0x61c88647;

    private static int nextHashCode() {
        return nextHashCode.getAndAdd(HASH_INCREMENT);
    }

    public int get() {
        return threadLocalHashCode & 15;
    }
}